# coding=utf8
# 全世界最帅的帅哥
from comment.modules import db
from sqlalchemy import ForeignKey
from datetime import datetime


class Letter(db.Model):
    """
    站内信的模型类
    """
    __tablename__ = 't_letter'
    id = db.Column(db.BIGINT, primary_key=True, autoincrement=True)
    sendID = db.Column(db.String(64), comment='发送者名字')
    recID = db.Column(db.BIGINT, comment='接收者ID')
    detail_id = db.Column(db.BIGINT, ForeignKey('t_letter_detail.id'), comment='消息详情主键')
    # 反向关联 Letter对象可以用letter_detail找到Letter_detail对象， Letter
    letter_detail = db.relationship('LetterDetail', backref=db.backref('letter', lazy=True))
    state = db.Column(db.Integer, comment='是否已读(0未读；1已读)', default=0)


class LetterDetail(db.Model):
    """
    站内信详情的模型类  1->多  详情是1
    """
    __tablename__ = 't_letter_detail'
    id = db.Column(db.BIGINT, primary_key=True, autoincrement=True)
    title = db.Column(db.String(64), comment='消息标题')
    detail = db.Column(db.String(256), comment='消息内容')
    pDate = db.Column(db.DateTime, default=datetime.now(), comment='发送时间')
